package com.lancoo.znbkxx.teacher.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.model.data.Classical
import kotlinx.android.synthetic.main.fmt_classical.view.*


/**
 * @author : wealive
 * @date   : 2020/3/16 17:18
 * @desc   :
 */
class StuAnswerAdapter(
        private val dialogTag: String,
        private val onAudioClickListener: AnswerListAdapter.OnAudioClickListener,
        layoutResId: Int,
        data: MutableList<Classical>
) :
        BaseQuickAdapter<Classical, BaseViewHolder>(layoutResId, data) {
    @SuppressLint("SetTextI18n")
    override fun convert(helper: BaseViewHolder, item: Classical?) {
        with(helper.itemView) {
            tv_stuName.text = "${item!!.StuName}的作答"
            helper.addOnClickListener(R.id.btn)
            if (dialogTag == "add") {
                btn.visibility = View.VISIBLE
                if (item.IsSelected == 0) {
                    btn.apply {
                        tag = "unselected"
                        text = "选用"
                        setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(context,
                                R.mipmap.aibk_icon_unselect_classical), null, null, null)
                    }
                } else {
                    btn.apply {
                        tag = "selected"
                        text = "取消选用"
                        setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(context,
                                R.mipmap.aibk_icon_select_classical), null, null, null)
                    }
                }
            } else {
                btn.visibility = View.GONE
            }
            val adapter = AnswerListAdapter(
                    R.layout.item_stu_answer,
                    item.AnswerList,
                    onAudioClickListener,
                    helper.layoutPosition
            )
            rv_stuAnswer.layoutManager = LinearLayoutManager(context)
            rv_stuAnswer.adapter = adapter
        }
    }
}